# Maintainer: Biswapriyo Nath <nathbappai@gmail.com>

_realname=typst
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.13.1
pkgrel=1
pkgdesc='A markup-based typesetting system for the sciences (mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://typst.app/'
msys2_repository_url='https://github.com/typst/typst/'
msys2_references=(
  'archlinux: typst'
  'purl: pkg:cargo/typst'
)
license=('spdx:Apache-2.0')
depends=("${MINGW_PACKAGE_PREFIX}-xz")
makedepends=("${MINGW_PACKAGE_PREFIX}-rust"
             "${MINGW_PACKAGE_PREFIX}-pkgconf"
             "${MINGW_PACKAGE_PREFIX}-openssl")
source=("https://github.com/typst/typst/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('2ffd8443668bc0adb59e9893f7904fd9f64dce8799a1930569f56a91305e8b71')

prepare() {
  cd ${_realname}-${pkgver}

  ${MINGW_PREFIX}/bin/cargo fetch --locked --target "$(rustc -vV | sed -n 's/host: //p')"
}

build() {
  cd ${_realname}-${pkgver}

  export OPENSSL_NO_VENDOR=1
  ${MINGW_PREFIX}/bin/cargo build -p typst-cli --frozen --release --all-features
}

package() {
  cd ${_realname}-${pkgver}

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
  install -Dm0755 -t "${pkgdir}${MINGW_PREFIX}/bin/" "target/release/typst.exe"
}
